package com.hzhr.iot.device.service;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.CygQuery;
import com.hzhr.iot.core.annotation.CygQuerys;
import com.hzhr.iot.core.annotation.CygService;
import com.hzhr.iot.core.constant.AccessModeEnum;
import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.device.constant.DeviceOptions;
import com.hzhr.iot.device.convertor.custom.AlarmDataCustomConvertor;
import com.hzhr.iot.device.dao.AlarmDataDao;
import com.hzhr.iot.device.dao.CollectDeviceDao;
import com.hzhr.iot.device.dao.IotDeviceDao;
import com.hzhr.iot.device.dao.helper.CollectDeviceDaoHelper;
import com.hzhr.iot.device.entity.AlarmDataEntity;
import com.hzhr.iot.device.entity.CollectDeviceEntity;
import com.hzhr.iot.device.entity.IotDeviceEntity;
import com.hzhr.iot.device.entity.ext.AlarmDataEntityExt;
import com.hzhr.iot.device.entity.ext.CollectDeviceEntityExt;
import com.hzhr.iot.device.model.alarmData.AlarmDataGetModel;
import com.hzhr.iot.device.model.alarmData.AlarmDataPostModel;
import com.hzhr.iot.device.queryModel.custom.AlarmDataCustomQueryModel;
import com.hzhr.iot.device.queryModel.custom.CollectDeviceCustomQueryModel;
import com.hzhr.iot.device.queryModel.custom.IotDeviceCustomQueryModel;
import com.hzhr.iot.device.service.base.BaseService;
import com.hzhr.iot.queues.sdk.model.pushQueues.PushQueuesModel;
import com.hzhr.iot.queues.sdk.model.pushQueues.PushQueuesPostModel;
import com.hzhr.iot.queues.sdk.service.Queues_PushQueuesService;
import com.hzhr.iot.user.sdk.model.user_info1.User_Info1Model;
import com.hzhr.iot.user.sdk.service.User_User_Info1Service;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.*;

@Service
@CygService(entity = AlarmDataEntity.class)
@CygQuerys({
        @CygQuery(name = "_equal_id", query = "equal_id", type = Integer.class),
        @CygQuery(name = "_equal_collectDeviceId", query = "equal_collectDeviceId", type = Integer.class),
        @CygQuery(name = "_equal_iotDeviceId", query = "equal_iotDeviceId", type = Integer.class),
        @CygQuery(name = "_equal_gasUserId", query = "equal_gasUserId", type = Integer.class),
        @CygQuery(name = "_equal_currentTm", query = "equal_currentTm", type = Date.class),
        @CygQuery(name = "_greaterthanorequal_currentTm", query = "greaterthanorequal_currentTm", type = Date.class),
        @CygQuery(name = "_lessthan_currentTm", query = "lessthan_currentTm", type = Date.class),

})
public class AlarmDataService extends BaseService {
    @Autowired
    AlarmDataCustomConvertor alarmDataCustomConvertor;
    @Autowired
    AlarmDataDao alarmDataDao;
    @Autowired
    AlarmDataService alarmDataService;
    @Autowired
    CollectDeviceDaoHelper collectDeviceDaoHelper;
    @Autowired
    User_User_Info1Service user_user_info1Service;
    @Autowired
    Queues_PushQueuesService queues_pushQueuesService;
    @Autowired
    DeviceOptions deviceOptions;
    @Autowired
    CollectDeviceDao collectDeviceDao;
    @Autowired
    IotDeviceDao iotDeviceDao;

    //region javadoc注释 : post
    /**
     * 创建报警数据 <br/><br/>
     * 步骤 : <br/>
     * 1. 如果报警数据已存在，直接返回 <br/>
     * 2. 新增报警数据 <br/>
     * 3. 向满足以下条件的用户推送报警消息 <br/>
     *  (1) 拥有该报警数据所对应的采集设备的数据权限 <br/>
     *  (2) 拥有“设备报警提醒”的角色 <br/>
     * 4. 返回信息 <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * @see AlarmDataPostModel body <br/>
     * @see AlarmDataGetModel result <br/>
     */ 
    //endregion
    //region 说明 : post
    //创建报警数据
    //步骤 :
    //1. 如果报警数据已存在，直接返回
    //2. 新增报警数据
    //3. 向满足以下条件的用户推送报警消息
    // (1) 拥有该报警数据所对应的采集设备的数据权限
    // (2) 拥有“设备报警提醒”的角色
    //4. 返回信息
    //endregion
    //region 参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/alarm-datas", method = RequestMethod.POST)
    //endregion
    @Transactional(rollbackFor = Exception.class)
    public AlarmDataGetModel post(Map<String, String> header, Map<String, Object> query,
                                    AlarmDataPostModel body) throws ServiceException {
        /* 如果报警数据已存在，直接返回 */
        AlarmDataCustomQueryModel alarmDataCustomQueryModel = new AlarmDataCustomQueryModel();
        alarmDataCustomQueryModel.setEqual_iotDeviceId(body.getIotDeviceId());
        alarmDataCustomQueryModel.setEqual_currentTm(new Date(body.getCurrentTm()));
        alarmDataCustomQueryModel.setEqual_isValid("1");
        int count = alarmDataDao.selectCount(alarmDataCustomQueryModel);
        if (count > 0) {
            AlarmDataGetModel result = new AlarmDataGetModel();
            result.setChangeCount(0);
            return result;
        }

        /* 新增报警数据 */
        AlarmDataEntity alarmData_1 = alarmDataCustomConvertor.alarmDataPostModel2entity(body);
        alarmData_1.setIsValid(CommonOptions.YES_NO.YES);
        alarmData_1.setCreateTime(new Date());
        alarmData_1.setState("1");
        int changeCount = alarmDataDao.insert(alarmData_1);

        /* 向满足以下条件的用户推送报警消息
            (1) 拥有该报警数据所对应的采集设备的数据权限
            (2) 拥有“设备报警提醒”的角色 */
        //查询采集设备信息
        Integer collectDeviceId = alarmData_1.getCollectDeviceId();
        CollectDeviceEntityExt collectDevice = null;
        if (collectDeviceId != null) {
            CollectDeviceCustomQueryModel queryModel = new CollectDeviceCustomQueryModel();
            queryModel.setEqual_id(collectDeviceId);
            queryModel.setEqual_isValid("1");
            queryModel.setShow(true);
            collectDevice = collectDeviceDao.selectExt(queryModel);
        }
        //查询拥有该报警数据所对应的采集设备的数据权限且拥有“设备报警提醒”的角色的用户
        List<User_Info1Model> user_info1Models = null;
        if (collectDevice != null) {
            String resourceCode = collectDevice.getResourceCode();
            String code = resourceCode.substring(6);
            List<String> resourceCodeList = new ArrayList<>();
            String code1 = resourceCode.substring(0, 6);
            resourceCodeList.add(code1);
            if (!StringUtils.isEmpty(code)) {
                for (int i = 2; i <= code.length(); i += 2) {
                    code1 += code.substring(i - 2, i);
                    resourceCodeList.add(code1);
                }
            }

            Map<String ,Object> query2 = new HashMap<>();
            query2.put("_in_resourceCode", resourceCodeList);
            query2.put("_roleId", 7);
            query2.put("_show", "list");
            user_info1Models = user_user_info1Service.get(initHeader(header, AccessModeEnum.GLOBAL), query2).getModelList();
        }
        //向用户推送报警消息
        if (user_info1Models != null && user_info1Models.size() > 0) {
            StringBuilder userNameListSb = new StringBuilder();
            StringBuilder phoneListSb = new StringBuilder();
            for (User_Info1Model user_info1Model:
            user_info1Models) {
                String userName = user_info1Model.getUserName();
                Long phone = user_info1Model.getPhone();
                if (!StringUtils.isEmpty(userName)) {
                    userNameListSb.append(userName + ",");
                }
                if (phone != null) {
                    phoneListSb.append(phone + ",");
                }
            }
            PushQueuesPostModel body1 = new PushQueuesPostModel();
            String userNameList = userNameListSb.toString();
            if (!StringUtils.isEmpty(userNameList)) {
                body1.setUserNameList(userNameList.substring(0, userNameList.length() - 1));
            }
            String phoneList = phoneListSb.toString();
            if (!StringUtils.isEmpty(phoneList)) {
                body1.setUserPhoneList(phoneList.substring(0, phoneList.length() - 1));
            }
            //查询物联网设备信息
            IotDeviceCustomQueryModel queryModel = new IotDeviceCustomQueryModel();
            queryModel.setEqual_id(body.getIotDeviceId());
            queryModel.setEqual_isValid("1");
            queryModel.setShow(true);
            IotDeviceEntity iotDevice = iotDeviceDao.selectEntity(queryModel);
            //配置推送信息并写入推送队列
            body1.setTitle("设备报警提醒");
            body1.setSummary("设备报警提醒：" + deviceOptions.getDesByCode("ALARM_TYPE", alarmData_1.getAlarmType()));
            String msg = "尊敬的用户您好，您所管理的物联网设备正在报警，请尽快处理。\n";
            msg += "设备信息如下：\n";
            msg += "设备类型：" + deviceOptions.getDesByCode("COLLECT_DEVICE_CATEGORY", collectDevice.getCategoryCode()) + "\n";
            msg += "设备编号：" + collectDevice.getCode() + "\n";
            msg += "加装设备类型：" + deviceOptions.getDesByCode("IOT_DEVICE_CATEGORY", iotDevice.getCategoryCode()) + "\n";
            msg += "加装设备编号：" + iotDevice.getCode() + "\n";
            msg += "报警类型：" + deviceOptions.getDesByCode("ALARM_TYPE", alarmData_1.getAlarmType()) + "\n";
            body1.setMsg(msg);

            if (iotDevice.getCategoryCode().equals("5")) {
                body1.setTargetId(iotDevice.getCode());
                body1.setTargetType("120602");
            } else {
                body1.setTargetId("1");
                body1.setTargetType("1");
            }
            Map<String, Object> query1 = new HashMap<>();
            queues_pushQueuesService.post(initHeader(header, AccessModeEnum.GLOBAL), query1, body1);
        }

        /* 返回信息 */
        query.put("_equal_id", alarmData_1.getId());
        AlarmDataGetModel result = alarmDataService.get(initHeader(header, AccessModeEnum.GLOBAL), query);
        result.setChangeCount(changeCount);
        return result;
    }


    //region javadoc注释 : get
    /**
     * 查询报警数据(根据报警时间降序排列) <br/><br/>
     * 1. 查询报警数据(根据报警时间降序排列) <br/>
     * 2. 返回信息 <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where alarmData.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_collectDeviceId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where alarmData.collectDeviceId = #{_equal_collectDeviceId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_iotDeviceId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where alarmData.iotDeviceId = #{_equal_iotDeviceId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_gasUserId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where alarmData.gasUserId = #{_equal_gasUserId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_currentTm : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where alarmData.currentTm = #{_equal_currentTm};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : long;<br/>
     * _greaterthanorequal_currentTm : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where alarmData.currentTm >= #{greaterthanorequal_currentTm};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : long;<br/>
     * _lessthan_currentTm : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where alarmData.currentTm < #{lessthan_currentTm};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : long;<br/><br/>
     * @throws ServiceException <br/>
     * @see AlarmDataGetModel result <br/>
     */ 
    //endregion
    //region 说明 : get
    //查询报警数据(根据报警时间降序排列)
    //1. 查询报警数据(根据报警时间降序排列)
    //2. 返回信息
    //endregion
    //region 参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where alarmData.id = #{equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_collectDeviceId", value = "筛选条件 : where alarmData.collectDeviceId = #{equal_collectDeviceId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_iotDeviceId", value = "筛选条件 : where alarmData.iotDeviceId = #{equal_iotDeviceId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_gasUserId", value = "筛选条件 : where alarmData.gasUserId = #{equal_gasUserId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_currentTm", value = "筛选条件 : where alarmData.currentTm = #{equal_currentTm}",required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "greaterthanorequal_currentTm", value = "筛选条件 : where alarmData.currentTm >= #{greaterthanorequal_currentTm}",required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "lessthan_currentTm", value = "筛选条件 : where alarmData.currentTm < #{lessthan_currentTm}",required = false, dataType = "long", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where alarmData.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_collectDeviceId", value = "筛选条件 : where alarmData.collectDeviceId = #{_equal_collectDeviceId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_iotDeviceId", value = "筛选条件 : where alarmData.iotDeviceId = #{_equal_iotDeviceId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_gasUserId", value = "筛选条件 : where alarmData.gasUserId = #{_equal_gasUserId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_currentTm", value = "筛选条件 : where alarmData.currentTm = #{_equal_currentTm}",required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "_greaterthanorequal_currentTm", value = "筛选条件 : where alarmData.currentTm >= #{greaterthanorequal_currentTm}",required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "_lessthan_currentTm", value = "筛选条件 : where alarmData.currentTm < #{lessthan_currentTm}",required = false, dataType = "long", paramType = "query"),

    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/alarm-datas", method = RequestMethod.GET)
    //endregion
    public AlarmDataGetModel get(Map<String, String> header, Map<String, Object> query) throws ServiceException {
        /* 查询报警数据(根据报警时间降序排列) */
        //生成查询模型
        AlarmDataCustomQueryModel queryModel = alarmDataCustomConvertor.alarmDataService_query2queryModel(query);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setOrderBy_currentTm("desc");
        //查询实体
        List<AlarmDataEntityExt> extList = null;
        String show = HzhrTypeUtil.object2string(query.get("_show"));
        if (!StringUtils.isEmpty(show)) {
            extList = alarmDataDao.selectExtList(queryModel);
        }
        //查询数量
        Integer total = null;
        Boolean showTotal = HzhrTypeUtil.object2boolean(query.get("_show_total"));
        if (showTotal != null && showTotal) {
            total = alarmDataDao.selectCount(queryModel);
        }

        /* 返回信息 */
        AlarmDataGetModel result = alarmDataCustomConvertor.extList2alarmDataGetModel(extList, total, null, query);
        return result;
    }
}

